#include "com_print.h"
#include "stm32wbxx_hal.h"


#define PRINT_BUF  (256)


extern UART_HandleTypeDef huart1;

// serial printf   uint64_t %llu
static uint8_t printf_buffer[PRINT_BUF] = {0};
int COMPrintf(const char* fmt, ...)
{
	va_list ap;
	va_start(ap, fmt );
	uint16_t len = vsprintf((char *)printf_buffer,fmt,ap);
	va_end( ap );
	
	HAL_UART_Transmit(&huart1, printf_buffer, len, 0xffffffff);

	return len;   
}

int COMPrintf_hexdump(uint8_t *parr,uint8_t len)
{
	char my_buf[PRINT_BUF];
	if(len < ((PRINT_BUF-1) /5))
	{
			memset(my_buf,0,sizeof(my_buf));
			for(int i=0;i<len;i++)
			{
					if((i+1)!=len)
						sprintf(my_buf+5*i,"0x%02x ",parr[i]);
					else
						sprintf(my_buf+5*i,"0x%02x \n",parr[i]);
			}

			COMPrintf(my_buf);
	}  
	return len;
}








